import type { SysDept } from '@nbase/db';
import type { IPaginationResponse, IDept } from '@nbase/shared';

/**
 * SysDept -> IDept 映射（对外返回使用）
 */
export function toDept(dept: SysDept): IDept {
  return {
    id: dept.id,
    code: dept.code,
    name: dept.name,
    parentId: dept.parentId,
    sort: dept.sort,
    leader: dept.leader,
    phone: dept.phone,
    email: dept.email,
    status: dept.status,
    description: dept.description,
    createdAt: dept.createdAt?.toISOString(),
    updatedAt: dept.updatedAt?.toISOString(),
  };
}

/**
 * 分页结果 SysDept -> IDept
 */
export function toDeptPage(page: IPaginationResponse<SysDept>): IPaginationResponse<IDept> {
  return {
    ...page,
    items: page.items.map(toDept),
  };
}

